//
//  BookContentViewController.m
//  book
//
//  Created by 云天 李 on 11-12-17.
//  Copyright (c) 2011年 __MyCompanyName__. All rights reserved.
//

#import "BookContentViewController.h"
#import "BookDB.h"
#import "BookIndex.h"
#import "BookContent.h"

@implementation BookContentViewController

@synthesize indexTitleLabel, bookContentTextView, backToIndexButton;
@synthesize indexid;

// 点击按钮返回目录列表
- (IBAction) backToIndex:(id)sender
{
    [self dismissModalViewControllerAnimated:YES];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
	
	BookContent *content = [BookDB fetchBookContent:self.indexid];
    
    [self.bookContentTextView setText: [content contenttext]];
    [self.indexTitleLabel setText:[[content bookIndex] title]];
    
    [content release];
    
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    [self.backToIndexButton setTitle:NSLocalizedString(@"btn.backtoindex.title", nil) forState:UIControlStateNormal];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void) dealloc
{
    [indexTitleLabel release];
    [bookContentTextView release];
    [backToIndexButton release];
    
    [super dealloc];
}

@end
